import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: 路由配置项
 *
 * hidden: true                     // 当设置 true 的时候该路由不会再侧边栏出现 如401，login等页面，或者如一些编辑页面/edit/1
 * alwaysShow: true                 // 当你一个路由下面的 children 声明的路由大于1个时，自动会变成嵌套的模式--如组件页面
 *                                  // 只有一个时，会将那个子路由当做根路由显示在侧边栏--如引导页面
 *                                  // 若你想不管路由下面的 children 声明的个数都显示你的根路由
 *                                  // 你可以设置 alwaysShow: true，这样它就会忽略之前定义的规则，一直显示根路由
 * redirect: noRedirect             // 当设置 noRedirect 的时候该路由在面包屑导航中不可被点击
 * name:'router-name'               // 设定路由的名字，一定要填写不然使用<keep-alive>时会出现各种问题
 * query: '{"id": 1, "name": "ry"}' // 访问路由的默认传递参数
 * roles: ['admin', 'common']       // 访问路由的角色权限
 * permissions: ['a:a:a', 'b:b:b']  // 访问路由的菜单权限
 * meta : {
 noCache: true                   // 如果设置为true，则不会被 <keep-alive> 缓存(默认 false)
 title: 'title'                  // 设置该路由在侧边栏和面包屑中展示的名字
 icon: 'svg-name'                // 设置该路由的图标，对应路径src/assets/icons/svg
 breadcrumb: false               // 如果设置为false，则不会在breadcrumb面包屑中显示
 activeMenu: '/system/user'      // 当路由设置了该属性，则会高亮相对应的侧边栏。
 }
 */

// 公共路由
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect')
      }
    ]
  },
  {
    path:'/map',
    component: ()=>import('@/components/testMap/index.vue'),
  },
  {
    path: '/register',
    component: () => import('@/views/register'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error/401'),
    hidden: true
  },
  //首次进入
  {
    path: '',
    redirect: '/welcome',
  },
  {
    // 欢迎页
    path: '/welcome',
    name: 'welcome',
    hidden: true,
    component: () => import('@/views/welcome.vue')
  },
  //登录页
  {
    path: '/login',
    component: () => import('@/views/login'),
    hidden: true
  },
  {
    // 首页
    path: '/home',
    name: 'home',
    component: () => import('@/views/xd/home/home.vue')
  },
  {
    // 大屏首页
    path: '/largeScreen',
    name: 'largeScreen',
    component: () => import('@/views/largeScreen/index.vue')
  },
  {
    // 网络用户抗定位-大屏
    path: '/userPositioningScreen',
    name: 'userPositioningScreen',
    component: () => import('@/views/largeScreen/userPositioningScreen/index.vue'),
    children: [

    ]
  },
  {
    // 用户抗位置泄露详情33333
    path: '/userPositioningScreen/details',
    name: 'details',
    component: () => import('@/views/largeScreen/userPositioningScreen/details.vue')
  },
  {
    // 用户抗位置泄露评估33333
    path: '/userPositioningScreen/compare',
    name: 'estimate',
    component: () => import('@/views/largeScreen/userPositioningScreen/estimate.vue')
  },
  {
    // 网络用户抗身份识别-大屏
    path: '/userIdentityScreen',
    name: 'userIdentityScreen',
    component: () => import('@/views/largeScreen/userIdentityScreen/index.vue')
  },
  {
    // 网络设备抗定位-大屏
    path: '/networkScreen',
    name: 'networkScreen',
    component: () => import('@/views/largeScreen/networkScreen/index.vue'),

  },
  {
    // 网络设备抗归属-大屏
    path: '/deviceHomeScreen',
    name: 'deviceHomeScreen',
    component: () => import('@/views/largeScreen/deviceHomeScreen/index.vue'),
  },
  {
    // 应用信息抗泄露-大屏
    path: '/applicationScreen',
    name: 'applicationScreen',
    component: () => import('@/views/largeScreen/applicationScreen/index.vue'),
  },

  {
    // 网络摄像头位置分析-大屏
    path: '/cameraPositionAnalysis',
    name: 'cameraPositionAnalysis',
    component: () => import('@/views/largeScreen/cameraPositionAnalysis/index.vue')
  },

  {
    path: '/networkScreendetails',
    name: 'networkScreendetails',
    component: () => import('@/views/xd/home/networkScreen2/details2.vue'),
  },
  {
    // 设备抗位置泄露评估33333
    path: '/networkestimate',
    name: 'estimate',
    component: () => import('@/views/xd/home/networkScreen2/estimate2.vue')
  },
  {
    // 设备抗位置泄露评估33333
    path: '/networkestimateDetail',
    name: 'estimateDetail',
    component: () => import('@/views/xd/home/networkScreen2/estimateDetail.vue')
  },
  {

    path: '/homeLogin',
    name: 'homeLogin',
    component: () => import('@/views/xd/Login/index.vue')
  },

  {
    // 设备抗社会属性分析评估444444444
    path: '/deviceestimate',
    name: 'index10',
    component: () => import('@/views/xd/home/devicehomeScreen4/estimate.vue')
  },

  {
    // 应用服务抗信息泄露-1
    path: '/1applicationScreen',
    name: '1applicationScreen',
    component: () => import('@/views/xd/home/applicationScreen1/details2.vue')
  },
  {
    // 网络用户抗身份识别大屏比较
    path: '/userIdentityScreen/compare',
    name: 'userIdentityScreencompare',
    component: () => import('@/views/largeScreen/userIdentityScreen/compare/index.vue')
  },
  {
    path: '/cs',
    name: '测试页面',
    component: () => import('@/views/xd/components/dialog/test.vue')
  },
  // 终端管理详情
  {
    path: '',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'applicationService/terminal/detail',
        component: () => import('@/views/applicationService/terminal/detail/index.vue'),
        name: '详情',
        meta: { title: '详情', icon: 'dashboard', affix: true }
      },
      {
        path: 'IPOwnershipProtection/dataStatistics/detail',
        component: () => import('@/views/IPOwnershipProtection/dataStatistics/detail/index.vue'),
        name: '抗归属任务管理详情',
        meta: { title: '抗归属任务管理详情', icon: 'dashboard', affix: true }
      }
    ]
  },
  {
    path: '/user',
    component: Layout,
    hidden: true,
    redirect: 'noredirect',
    children: [
      {
        path: 'profile',
        component: () => import('@/views/system/user/profile/index'),
        name: 'Profile',
        meta: {title: '个人中心', icon: 'user'}
      }
    ]
  }
]

// 动态路由，基于用户权限动态去加载
export const dynamicRoutes = [
  {
    path: '//systemuser-auth',
    component: Layout,
    hidden: true,
    permissions: ['system:user:edit'],
    children: [
      {
        path: 'role/:userId(\\d+)',
        component: () => import('@/views/system/user/authRole'),
        name: 'AuthRole',
        meta: {title: '分配角色', activeMenu: '/system/user'}
      }
    ]
  },
  {
    path: '/system/role-auth',
    component: Layout,
    hidden: true,
    permissions: ['system:role:edit'],
    children: [
      {
        path: 'user/:roleId(\\d+)',
        component: () => import('@/views/system/role/authUser'),
        name: 'AuthUser',
        meta: {title: '分配用户', activeMenu: '/system/role'}
      }
    ]
  },
  {
    path: '/system/dict-data',
    component: Layout,
    hidden: true,
    permissions: ['system:dict:list'],
    children: [
      {
        path: 'index/:dictId(\\d+)',
        component: () => import('@/views/system/dict/data'),
        name: 'Data',
        meta: {title: '字典数据', activeMenu: '/system/dict'}
      }
    ]
  },
  {
    path: '/monitor/job-log',
    component: Layout,
    hidden: true,
    permissions: ['monitor:job:list'],
    children: [
      {
        path: 'index/:jobId(\\d+)',
        component: () => import('@/views/monitor/job/log'),
        name: 'JobLog',
        meta: {title: '调度日志', activeMenu: '/monitor/job'}
      }
    ]
  },
  {
    path: '/system/algorithm-log',
    component: Layout,
    hidden: true,
    permissions: ['system:algorithm:list'],
    children: [
      {
        path: 'index/:jobId(\\d+)',
        component: () => import('@/views/system/algorithm/log'),
        name: 'JobLog',
        meta: {title: '算法日志', activeMenu: '/system/algorithm'}
      }
    ]
  },
  {
    path: '/tool/gen-edit',
    component: Layout,
    hidden: true,
    permissions: ['tool:gen:edit'],
    children: [
      {
        path: 'index/:tableId(\\d+)',
        component: () => import('@/views/tool/gen/editTable'),
        name: 'GenEdit',
        meta: {title: '修改生成配置', activeMenu: '/tool/gen'}
      }
    ]
  },
  {
    path: '/xsystem',
    // component: Layout,
    redirect: '/8jkbs/multilayer',
    name: '应用服务抗信息泄露',
    meta: {
      title: '应用服务抗信息泄露',
      icon: 'el-icon-edit-outline'
    },
    hidden: false,
    children: [
    //   {
    //   path: 'terminalManagement',
    //   component: () => import('@/views/applicationService/terminal/index.vue'),
    //   name: '终端管理',
    //   meta: {
    //     title: '终端管理',
    //     icon: 'el-icon-headset'
    //   },
    //   hidden: false
    // },
    {
      path: 'apk',
      component: () => import('@/views/applicationService/apk/index.vue'),
      name: 'apk管理',
      meta: {
        title: 'apk管理',
        icon: 'el-icon-headset'
      },
      hidden: false
    }, {
      path: 'data',
      component: () => import('@/views/applicationService/data/index.vue'),
      name: '数据分析',
      meta: {
        title: '数据分析',
        icon: 'el-icon-headset'
      },
      hidden: false
    }]
  },
  {
    path: '/networkEquipment',
    // component: Layout,
    redirect: '/8jkbs/multilayer',
    name: '网络设备抗关联服务',
    meta: {
      title: '网络设备抗关联服务',
      icon: 'el-icon-edit-outline'
    },
    hidden: false,
    children: [{
      path: 'equipment',
      component: () => import('@/views/networkEquipment/equipment/index.vue'),
      name: '设备管理',
      meta: {
        title: '设备管理',
        icon: 'el-icon-headset'
      },
      hidden: false
    },
      {
      path: 'antiLocalization',
      component: () => import('@/views/networkEquipment/antiLocalization/index.vue'),
      name: '抗定位管理',
      meta: {
        title: '抗定位管理',
        icon: 'el-icon-headset'
      },
      hidden: false
    },
      {
      path: 'antiAttributive',
      component: () => import('@/views/networkEquipment/antiAttributive/index.vue'),
      name: '抗归属管理',
      meta: {
        title: '抗归属管理',
        icon: 'el-icon-headset'
      },
      hidden: false
    }]
  },

  {
    path: '/networkUser',
    // component: Layout,
    redirect: '/8jkbs/multilayer',
    name: '网络用户抗关联服务',
    meta: {
      title: '网络用户抗关联服务',
      icon: 'el-icon-edit-outline'
    },
    hidden: false,
    children: [{
      path: 'user',
      component: () => import('@/views/networkUser/user/index.vue'),
      name: '用户管理',
      meta: {
        title: '用户管理',
        icon: 'el-icon-headset'
      },
      hidden: false
      // children: [{
      //   path: 'userdetails',
      //   component: () => import('@/views/networkUser/antiAttributive/details_page.vue'),
      //   name: '用户详情页',
      //   meta: {
      //     title: '用户管理详情页',
      //     icon: 'el-icon-headset'
      //   },
      //   hidden: false,
      // }]
    },
    //   {
    //   path: 'userdetails',
    //   component: () => import('@/views/networkUser/user/details.vue'),
    //   name: '用户详情页',
    //   meta: {
    //     title: '用户详情页',
    //     icon: 'el-icon-headset'
    //   },
    //   hidden: true
    // },

      {
      path: 'antiLocalization',
      component: () => import('@/views/networkUser/antiLocalization/index.vue'),
      name: '用户抗定位服务',
      meta: {
        title: '用户抗定位服务',
        icon: 'el-icon-headset'
      },
      hidden: false
    }, {
      path: 'userLocaldetails',
      component: () => import('@/views/networkUser/antiLocalization/details_page.vue'),
      name: '用户定位详情页',
      meta: {
        title: '用户定位详情页',
        icon: 'el-icon-headset'
      },
      hidden: true
    }, {
      path: 'antiAttributive',
      component: () => import('@/views/networkUser/antiAttributive/index.vue'),
      name: '用户抗身份识别服务',
      meta: {
        title: '用户抗身份识别服务',
        icon: 'el-icon-headset'
      },
      hidden: false
      // children: [{
      //   path: 'antiAttributivedetails',
      //   component: () => import('@/views/networkUser/antiAttributive/details_page.vue'),
      //   name: '用户抗身份识别服务详情页',
      //   meta: {
      //     title: '用户抗身份识别服务详情页',
      //     icon: 'el-icon-headset'
      //   },
      //   hidden: false,
      // }]
    }]
  }
]

// 防止连续点击多次路由报错
let routerPush = Router.prototype.push;
let routerReplace = Router.prototype.replace;
// push
Router.prototype.push = function push(location) {
  return routerPush.call(this, location).catch(err => err)
}
// replace
Router.prototype.replace = function push(location) {
  return routerReplace.call(this, location).catch(err => err)
}

export default new Router({
  mode: 'history', // 去掉url中的#
  scrollBehavior: () => ({y: 0}),
  routes: constantRoutes
})
